package com.yiwei.hdb.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.yiwei.hdb.R;
import com.yiwei.hdb.adapter.V4HelpAdapter;
import com.yiwei.hdb.api.Api;
import com.yiwei.hdb.constant.Const;
import com.yiwei.hdb.constant.UserGlobal;
import com.yiwei.hdb.util.Network;
import com.yiwei.hdb.util.PreferenceUtils;
import com.yiwei.hdb.util.RxLifeUtil;
import com.yiwei.hdb.util.ToastUtil;
import com.yiwei.hdb.util.Util;
import com.yiwei.hdb.view.Dialog;
import com.yiwei.hdb.view.V19FrameLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by Administrator on 2018/6/10.
 */

public class V4HelpCenterActivity extends BaseActivity {
    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.txt_right)
    TextView txtRight;
    @BindView(R.id.layout_title)
    V19FrameLayout layoutTitle;
    @BindView(R.id.list)
    RecyclerView list;
    @BindView(R.id.btn_wechat)
    TextView btnWechat;
    @BindView(R.id.btn_call)
    TextView btnCall;
    private Unbinder unbinder;
    private V4HelpAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_help_v4);
        initBar();
        unbinder = ButterKnife.bind(this);
        init();
    }

    private void init() {
        setIsNeedCheckLogout(false);
        txtTitle.setText("帮助中心");
        adapter = new V4HelpAdapter(this);
        list.setAdapter(adapter);
        getHelp();
    }

    public void getHelp() {
        if (!Network.checkNetwork(this)) {
            ToastUtil.makeText(this, "网络连接失败");
            return;
        }
        loadingDialog.show();
        Api.api_service.getHelpInfo().compose(RxLifeUtil.NocheckOn(this)).
                doFinally(() -> {
                    try {
                        loadingDialog.dismiss();

                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    adapter.update(result.getData());
                });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
        unbinder = null;
    }

    @OnClick(R.id.btn_back)
    public void onViewClicked() {
        finish();
    }

    @OnClick({R.id.btn_wechat, R.id.btn_call})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_wechat:
                Util.startActivity(this, WechatChatActivity.class);
                break;
            case R.id.btn_call:
                String mPhoneNum = PreferenceUtils.getString(getApplicationContext(), Const.KEY.SERVICE_PHONE, "");
                Dialog.showDefaultV3Dialog(this, "提示", "请确认拨打花点呗官方电话" + mPhoneNum, "取消", "确定", new Dialog.DialogDefaultClickListener() {
                    @Override
                    public void confirm() {
                        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + mPhoneNum));
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);
                    }

                    @Override
                    public void cancel() {

                    }
                });
                break;
        }
    }
}
